////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation.  All rights reserved.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// Portions Copyright (c) 2010-2011 Kentaro Sekimoto  All rights reserved.
////////////////////////////////////////////////////////////////////////////

#include <tinyhal.h>
#include <Drivers\fs\fat\fat_fs.h>

#define USE_WEAR_LEVELING   // Bl_addDevices.cpp and FS_congig.cpp
//#define FAT_ON_SD
#define FAT_ON_NAND

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rwdata = "g_AvailableFSInterfaces"
#endif

extern FILESYSTEM_DRIVER_INTERFACE g_FAT32_FILE_SYSTEM_DriverInterface;
extern STREAM_DRIVER_INTERFACE g_FAT32_STREAM_DriverInterface;

#if defined(FAT_ON_SD)
extern struct BlockStorageDevice  g_SD_BS;
FileSystemVolume g_SD_FS;
extern struct SD_BL_CONFIGURATION g_SD_BL_Config;
#endif

#if defined(ENABLE_NAND)
#if defined(FAT_ON_NAND)
extern struct BlockStorageDevice  g_TC58NVG3S0F_BS;
FileSystemVolume g_NAND_FS;

#if defined(USE_WEAR_LEVELING)
FILESYSTEM_DRIVER_INTERFACE g_SK_FM4_FAT32_FILE_SYSTEM_DriverInterface =
{
    &FAT_FS_Driver::FindOpen,
    &FAT_FS_Driver::FindNext,
    &FAT_FS_Driver::FindClose,

    &FAT_FS_Driver::GetFileInfo,

    &FAT_FS_Driver::CreateDirectory,
    &FAT_FS_Driver::Move,
    &FAT_FS_Driver::Delete,

    &FAT_FS_Driver::GetAttributes,
    &FAT_FS_Driver::SetAttributes,

    &FAT_FS_Driver::Format,
    &FAT_FS_Driver::IsLoadableMedia,
    &FAT_FS_Driver::GetSizeInfo,
    &FAT_FS_Driver::FlushAll,
    &FAT_FS_Driver::GetVolumeLabel,

    "FAT",
    FS_DRIVER_ATTRIBUTE__FORMAT_REQUIRES_ERASE,
};
#endif
#endif
#endif

void FS_AddVolumes()
{
#if defined(ENABLE_NAND)
    FileSystemVolumeList::AddVolume( &g_NAND_FS, "ROOT", 0, 0, &g_FAT32_STREAM_DriverInterface, &g_FAT32_FILE_SYSTEM_DriverInterface, &g_TC58NVG3S0F_BS, 0, FALSE );
#endif
}

void FS_MountRemovableVolumes()
{
#if defined(FAT_ON_SD)
#endif
}

FILESYSTEM_INTERFACES g_AvailableFSInterfaces[] =
{
#if defined(ENABLE_NAND)
#if defined(USE_WEAR_LEVELING)
    { &g_SK_FM4_FAT32_FILE_SYSTEM_DriverInterface, &g_FAT32_STREAM_DriverInterface }
#else
    { &g_FAT32_FILE_SYSTEM_DriverInterface, &g_FAT32_STREAM_DriverInterface }
#endif
#endif
};

const size_t g_InstalledFSCount = ARRAYSIZE(g_AvailableFSInterfaces);
//const size_t g_InstalledFSCount = 1;

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rwdata
#endif
